/**
 * Created by Administrator on 2018/12/1 0001.
 */
const mongoose = require('mongoose');
const authorSchema = new mongoose.Schema({
    name: {
        type: String,  // 名字
        required: true
    },
    sexCode: {
        type: String,
        default: 1,
        enum: [1,2,3]    //1男 2女 3未知
    },
    description: {
        type: String,
       default: ''
    }
})
authorSchema.statics = {
    findDocs: function (findObj,showHandle,handleObj,cb) {
        this.find(findObj,showHandle,handleObj,(err,docs) => {
            if(err) {
                console.log(err);
                cb(9999);
            }else {
                cb(docs);
            }
        })
    },
    deleteDocs: function (deletebj,cb) {
        this.remove(deletebj,(err,docs) => {
            if(err) {
                console.log(err);
                cb(9999);
            }else {
                console.log(docs)
                cb(true);
            }
        })
    },
    updateDocs: function (updateOpt,{updateObj},cb) {
        this.update(updateOpt,{updateObj},(err,docs) => {
            if(err) {
                console.log(err);
                cb(9999);
            }else {
                console.log(docs)
                cb(true);
            }
        })
    }
}
authorSchema.methods.addDocs = function(cb) {
    this.save((err,docs) => {
        if(err) {
            cb(9999);
        }else {
            cb(true);
        }
    })
}
const authorModel = mongoose.model('author',authorSchema); //创建集合（表）


module.exports = authorModel;
